import request from '@/utils/request'

import { AxiosPromise } from 'axios'
import { SysDealerBo } from '@/api/system/dealer/types'

enum Api {
  list = '/system/dealer/list',
  add = '/system/dealer/add',
  edit = '/system/dealer/edit',
  delete = '/system/dealer/delete',
  batchDelete = '/system/dealer/batchDelete',
  changeStatus = '/system/dealer/changeStatus',
  optionSelect = '/system/dealer/optionSelect',
}

// 列表
export function dealerList(query?: any): AxiosPromise<any> {
  return request({
    url: Api.list,
    method: 'post',
    data: query,
  })
}

// 编辑、保存
export const dealerSave = (data: SysDealerBo) => {
  return request({
    url: data.id ? Api.edit : Api.add,
    method: 'post',
    data,
  })
}

// 删除
export function dealerDelete(id: string | Array<string>) {
  return request({
    url: Api.delete,
    method: 'post',
    data: id,
  })
}

// 批量删除
export const dealerBatchDelete = (data: (string | number)[]) => {
  return request({
    url: Api.batchDelete,
    method: 'post',
    data,
  })
}

// 选项列表
export function optionSelect(query?: any): AxiosPromise<any> {
  return request({
    url: Api.optionSelect,
    method: 'post',
    data: query,
  })
}

// 状态修改
export function changeStatus(id: string | number, status: number) {
  const data = {
    id,
    status,
  }
  return request({
    url: Api.changeStatus,
    method: 'post',
    data,
  })
}
